package com.example.javaeekeshe.service.impl;

import com.example.javaeekeshe.mapper.AccountMapper;
import com.example.javaeekeshe.pojo.AccountBean;
import com.example.javaeekeshe.service.IAccountService;
import com.example.javaeekeshe.utils.encryUtils.IEncryption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AccountServiceImpl implements IAccountService {
    @Resource(name = "Md5")
    IEncryption encry2;
    @Resource(name = "Des")
    IEncryption encry1;
    @Autowired
    AccountMapper accountMapper;

    @Override
    public AccountBean existByAccount(String userName, String password) {
        String encry = encry2.encry(encry1.encry(password));
        return accountMapper.existByAccount(userName, encry);
    }

    @Override
    public Integer existByUserName(String userName) {
        return accountMapper.existByUsername(userName);
    }

    @Override
    public void saveUser(String username, String password) {
        AccountBean account=new AccountBean();
        account.setUsername(username);
        account.setName(username);
        account.setPassword(encry2.encry(encry1.encry(password)));
        accountMapper.insertUser(account);

    }

    @Override
    public void Update(String username, String password) {
        AccountBean account=new AccountBean();
        account.setUsername(username);
        account.setName(username);
        account.setPassword(encry2.encry(encry1.encry(password)));
        accountMapper.Update(account);
    }

    @Override
    public void rename(AccountBean accountBean) {
        accountMapper.rename(accountBean);
    }

    @Override
    public void insertAdmin(AccountBean accountBean) {
        accountBean.setPassword(encry2.encry(encry1.encry(accountBean.getPassword())));
        accountMapper.insertAdmin(accountBean);
    }


}
